<template>
  <div class="material-receipt-maintenance-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>收料维护</span>
          <div class="header-operations">
            <el-button type="primary" @click="showCreateDialog">新建收料单</el-button>
            <el-button type="primary" @click="handleBatchApprove">批量审核</el-button>
          </div>
        </div>
      </template>

      <el-table :data="receipts" style="width: 100%">
        <el-table-column prop="type" label="类型" />
        <el-table-column prop="status" label="状态" />
        <!-- ... 其他表格列 ... -->
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </el-card>

    <!-- 新增收料单对话框 -->
    <el-dialog title="新建收料单" v-model="createDialogVisible" width="30%">
      <el-form :model="newReceiptForm" label-width="100px">
        <el-form-item label="类型">
          <el-select v-model="newReceiptForm.type" placeholder="请选择类型">
            <el-option label="采购收料" value="purchase"></el-option>
            <el-option label="退货收料" value="return"></el-option>
            <el-option label="其他收料" value="other"></el-option>
          </el-select>
        </el-form-item>
        <!-- ... 其他表单项 ... -->
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="createDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleCreate">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage, ElMessageBox, ElTable, ElTableColumn, ElPagination, ElDialog, ElForm, ElFormItem, ElSelect, ElOption, ElButton } from 'element-plus';

const receipts = ref([
  // 示例数据
  { type: '类型A', status: 'true' },
  // ... 其他收料单数据 ...
]);

const newReceiptForm = ref({
  type: '',
  // ... 其他表单项数据 ...
});

const createDialogVisible = ref(false);

const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(100); // 假设总数据量为100

const showCreateDialog = () => {
  createDialogVisible.value = true;
};

const handleCreate = () => {
  console.log('Creating new receipt:', newReceiptForm.value);
  // 假设新增成功，添加到列表并重置表单
  receipts.value.push({ ...newReceiptForm.value, status: 'draft' });
  createDialogVisible.value = false;
  newReceiptForm.value = {
    type: '',
    // ... 重置其他表单项数据 ...
  };
  ElMessage.success('新建收料单成功');
};

const handleBatchApprove = () => {
  // 实现批量审核逻辑
};

const handleSizeChange = (newSize) => {
  pageSize.value = newSize;
  // handleSearch(); // 假设这是搜索方法
};

const handleCurrentChange = (newPage) => {
  currentPage.value = newPage;
  // handleSearch(); // 假设这是搜索方法
};

</script>

<style scoped>
.material-receipt-maintenance-container {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-operations {
  /* 样式可以根据需要调整 */
}

.pagination {
  margin-top: 20px;
  text-align: right;
}
</style>
